/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.swirrel.installer;

import java.awt.Component;
import java.awt.event.MouseWheelListener;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import org.swirrel.annotation.MouseWheelMoved;
import org.swirrel.listener.SwirrelMouseWheelListener;
import org.swirrel.util.MethodCall;

/**
 *
 * @author Gronau
 */
public class MouseWheelListenerInstaller extends AbstractListenerInstaller implements SwirrelListenerInstaller {

    public MouseWheelListenerInstaller() {
        super(Arrays.<Class<? extends Annotation>>asList(MouseWheelMoved.class),
                Arrays.<Class<?>>asList(Component.class));
    }

    public boolean isListenerAlreadySet(Object obj) {
        for (MouseWheelListener ml : ((Component) obj).getMouseWheelListeners()) {
            if (ml instanceof SwirrelMouseWheelListener) {
                return true;
            }
        }
        return false;
    }

    public void registerListener(Field field, Component comp, List<MethodCall> methodCalls) throws IllegalAccessException {
        ((Component) field.get(comp)).addMouseWheelListener(
                new SwirrelMouseWheelListener(methodCalls.get(0)));
    }
}
